﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TTBusiness.DB_Linq;
using TTBusiness.ClassDB;
using TTBusiness;
namespace TTMarketing.Admin
{
    public partial class CateDetail : System.Web.UI.Page
    {
        clsBSCateDetail objDB = new clsBSCateDetail();
        protected void Page_Load(object sender, EventArgs e)
        {
            divmessage.InnerHtml = "";
            divmessage2.InnerHtml = "";
        }

        protected void cmbClose_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            if (Convert.ToInt32(e.Value) == 1)
            {
                plDetail.Visible = true;
            }
            else
            {
                plDetail.Visible = false;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {

                tblCate_Detail obj = new tblCate_Detail();
                obj.CateID = Convert.ToInt32(this.cmbCate.SelectedValue);
                obj.DetailID = Convert.ToInt32(this.cmbDetail.SelectedValue);
                obj.Number = Convert.ToInt32(this.cmbNumber.SelectedValue);
                objDB.insert(obj);
                divmessage.InnerHtml = clsBSMessageAdmin.MessageSuccess("Thành công : ", "Cập nhật thành công").ToString();
                this.rgdGrid.Rebind();
                this.cmbDetail.DataBind();
            }
            catch (Exception ex)
            {
                divmessage.InnerHtml = clsBSMessageAdmin.MessageError("Lỗi : ", "Gặp lỗi không thể cập nhật : " + ex.Message).ToString();
            }
        }

        protected void rgdGrid_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            try
            {
                if (e.CommandName.Equals("delete"))
                {
                    objDB.delete(Convert.ToInt32(e.CommandArgument));
                    divmessage2.InnerHtml = clsBSMessageAdmin.MessageSuccess("Thành công : ", "Đã xóa thành công!").ToString();
                    this.rgdGrid.Rebind();
                    this.cmbDetail.DataBind();
                }
            }
            catch (Exception ex)
            {
                divmessage2.InnerHtml = clsBSMessageAdmin.MessageError("Lỗi : ", "Gặp lỗi không thể xóa được" + ex.Message).ToString();
            }
        }

        protected void cmbCate_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            try
            {
                this.rgdGrid.Rebind();
                this.cmbDetail.DataBind();
            }
            catch (Exception ex)
            {

                divmessage2.InnerHtml = clsBSMessageAdmin.MessageError("Lỗi : ", "Gặp lỗi " + ex.Message).ToString();
            }
        }

        protected void cmbCate_DataBound(object sender, EventArgs e)
        {
            try
            {
                this.rgdGrid.Rebind();
                this.cmbDetail.DataBind();
            }
            catch (Exception ex)
            {

                divmessage2.InnerHtml = clsBSMessageAdmin.MessageError("Lỗi : ", "Gặp lỗi " + ex.Message).ToString();
            }
        }

        protected void cmbType_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            try
            {
                this.cmbCate.DataBind();
            }
            catch (Exception ex)
            {

                divmessage2.InnerHtml = clsBSMessageAdmin.MessageError("Lỗi : ", "Gặp lỗi " + ex.Message).ToString();
            }
        }

        protected void cmbType_DataBound(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    this.cmbCate.DataBind();
                }
                catch (Exception ex)
                {

                    divmessage2.InnerHtml = clsBSMessageAdmin.MessageError("Lỗi : ", "Gặp lỗi " + ex.Message).ToString();
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}